using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;

namespace SolanumSolstice_Windows
{
    public class GameSelection
    {
        private Texture2D texture;
        private int startX;
        private int startY;
        private int endX;
        private int endY;
        private bool isActive;

        #region Accessors

        public int StartX
        {
            get
            {
                return startX;
            }
            set
            {
                startX = value;
            }
        }

        public int StartY
        {
            get
            {
                return startY;
            }
            set
            {
                startY = value;
            }
        }

        public int EndX
        {
            get
            {
                return endX;
            }
            set
            {
                endX = value;
            }
        }

        public int EndY
        {
            get
            {
                return endY;
            }
            set
            {
                endY = value;
            }
        }

        public bool IsActive
        {
            get
            {
                return isActive;
            }
            set
            {
                isActive = value;
            }
        }

        #endregion

        public GameSelection(Texture2D texture, int startX, int startY)
        {
            this.texture = texture;
            this.startX = startX;
            this.startY = startY;
            this.endX = startX;
            this.endY = startY;
            isActive = true;
        }

        public GameSelection(Texture2D texture, Vector2 start)
        {
            this.texture = texture;
            this.startX = (int)start.X;
            this.startY = (int)start.Y;
            this.endX = (int)start.X;
            this.endY = (int)start.Y;
            isActive = true;
        }



        public void Draw(SpriteBatch spritebatch, int mapFocusX, int mapFocusY)
        {
            if (isActive)
            {
                if (endX < startX && endY > startY)
                {
                    spritebatch.Draw(texture, new Rectangle(endX - mapFocusX, startY - mapFocusY, startX - endX, endY - startY), Color.White);
                }
                else if (endX > startX && endY < startY)
                {
                    spritebatch.Draw(texture, new Rectangle(startX - mapFocusX, endY - mapFocusY, endX - startX, startY - endY), Color.White);
                }
                else
                {
                    spritebatch.Draw(texture, new Rectangle(startX - mapFocusX, startY - mapFocusY, endX - startX, endY - startY), Color.White);
                }
            }
        }

        public void SetStartPosition(Vector2 position)
        {
            startX = (int)position.X;
            startY = (int)position.Y;
        }
    }
}
